package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontAdminInfo;
import cn.jsj.object.FrontAssistInfo;
import cn.jsj.object.FrontLawyer;
import cn.jsj.object.FrontPracLawyer;
import cn.jsj.utils.ProduceJsonData;
import cn.jsj.utils.SysLogger;
/**
 * 个人信息查看
 * @author LI
 *
 */
 public class PersonalInfoScan extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("查看个人信息");

		//获得参数 role:1.律师 2.实习律师 3.行政人员
		int userId=Integer.parseInt(request.getParameter("userId"));
		int role=Integer.parseInt(request.getParameter("role"));

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("           "+role+"        "+userId);

		//根据role的值加载不同的用户
		//如果为律师
		if(role==1){
			cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
			cn.jsj.pojo.TblLawyer tl=tld.getLawyerInfoFromId(userId);


			//前台律师信息对象队列
			java.util.List<FrontLawyer> frontLawyerInfo=new java.util.LinkedList<FrontLawyer>();

			//改造成前台需要的律师信息对象
			cn.jsj.object.rebuild.LawyerInfoRebuild lir=new cn.jsj.object.rebuild.LawyerInfoRebuild();
				cn.jsj.object.FrontLawyer fl=lir.rebuildLawyer(tl);
				frontLawyerInfo.add(fl);

			//改造成JSON型数据
			ProduceJsonData pjd=new ProduceJsonData();
		String resultData=	pjd.jsonFromRecord(frontLawyerInfo);

		//调试信息
		SysLogger.PrintInfo(resultData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(resultData);
		pw.flush();
		pw.close();
		}

		//如果为行政人员
		if(role==3){
			cn.jsj.dao.TblAdminPersonnelDAO tapd=new cn.jsj.dao.TblAdminPersonnelDAO();
			cn.jsj.pojo.TblAdminPersonnel tap=tapd.getAdminFromId(userId);


			//前台实习律师信息对象队列
			java.util.List<FrontAdminInfo> frontAdminInfoList=new java.util.LinkedList<FrontAdminInfo>();

			//改造成前台需要的实习律师信息对象
			cn.jsj.object.rebuild.AdminInfoRebuild air=new cn.jsj.object.rebuild.AdminInfoRebuild();
				cn.jsj.object.FrontAdminInfo fal=air.rebuildAdmin(tap);
				frontAdminInfoList.add(fal);

			//改造成JSON型数据
			ProduceJsonData pjd=new ProduceJsonData();
		String resultData=	pjd.jsonFromRecord(frontAdminInfoList);
		//调试信息
		SysLogger.PrintInfo(resultData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(resultData);
		pw.flush();
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}